import utils from "./utils";
export default {
  methods: {
    openFile() {
      document.querySelector(`#el-upload${this.count} .el-upload`).click();
      // this.$refs[`el-upload${this.count}`].$children[1].$el.click()
    },
    clearFile() {
      this.$refs[`el-upload${this.count}`].clearFiles();
      while (this.fileList.pop()) {}
    },
    
    handlePictureCardUpload(file) {
      // this.$refs[`el-upload${this.count}`].clearFiles();
      // while (this.fileList.pop()) {}
      this.openFile();
    },
    handleDownload(file) {
      console.log(file);

      fetch(this.imgUrl+file.mediaUrl).then((res) => {
        console.log(res);
        res.blob().then((blob) => {
          const blobUrl = window.URL.createObjectURL(blob);
          // 这里的文件名根据实际情况从响应头或者url里获取
          // const filename = fileName;
          const a = document.createElement("a");
          a.href = blobUrl;
          // a.download = filename;
          a.click();
          window.URL.revokeObjectURL(blobUrl);
        });
      });
    },
    handlePictureCardPreview(file, ref) {
      // let uploadFiles = this.$refs[ref].uploadFiles;
      // console.log(this.fileTempList);

      this.$hevueImgPreview({
        multiple: true,
        nowImgIndex: this.fileTempList
          .filter((item) => item.fileType == "image")
          .findIndex((item) => item.uid == file.uid),
        imgList: this.fileTempList
          .filter((item) => item.fileType == "image")
          .map((item) => item.url),
      });
    },
    handleVideoPreview(file, ref) {
      this.Screen(this.$refs[ref]);
    },
    Screen(element) {
      if (element.requestFullscreen) {
        element.requestFullscreen();
      } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
      } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
      } else if (element.oRequestFullscreen) {
        element.oRequestFullscreen();
      } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullScreen();
      } else {
        var docHtml = document.documentElement;
        var docBody = document.body;
        var videobox = document.getElementById("video");
        var cssText = "width:100%;height:100%;overflow:hidden;";
        docHtml.style.cssText = cssText;
        docBody.style.cssText = cssText;
        element.style.cssText = cssText + ";" + "margin:0px;padding:0px;";
        document.IsFullScreen = true;
      }
    },
  },
};
